/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.NameSequence;
import org.quality4spl.fm.cvm.NamedElement;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Name Sequence</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.NameSequenceImpl#getNames <em>Names</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.NameSequenceImpl#getInitialSize <em>Initial Size</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class NameSequenceImpl extends CVMElementImpl implements NameSequence {
	/**
	 * The cached value of the '{@link #getNames() <em>Names</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNames()
	 * @generated
	 * @ordered
	 */
	protected EList<NamedElement> names;

	/**
	 * The default value of the '{@link #getInitialSize() <em>Initial Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInitialSize()
	 * @generated
	 * @ordered
	 */
	protected static final int INITIAL_SIZE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getInitialSize() <em>Initial Size</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInitialSize()
	 * @generated
	 * @ordered
	 */
	protected int initialSize = INITIAL_SIZE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected NameSequenceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.NAME_SEQUENCE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<NamedElement> getNames() {
		if (names == null) {
			names = new EObjectResolvingEList<NamedElement>(NamedElement.class, this, CvmPackage.NAME_SEQUENCE__NAMES);
		}
		return names;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getInitialSize() {
		return initialSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInitialSize(int newInitialSize) {
		int oldInitialSize = initialSize;
		initialSize = newInitialSize;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.NAME_SEQUENCE__INITIAL_SIZE, oldInitialSize, initialSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.NAME_SEQUENCE__NAMES:
				return getNames();
			case CvmPackage.NAME_SEQUENCE__INITIAL_SIZE:
				return getInitialSize();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.NAME_SEQUENCE__NAMES:
				getNames().clear();
				getNames().addAll((Collection<? extends NamedElement>)newValue);
				return;
			case CvmPackage.NAME_SEQUENCE__INITIAL_SIZE:
				setInitialSize((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.NAME_SEQUENCE__NAMES:
				getNames().clear();
				return;
			case CvmPackage.NAME_SEQUENCE__INITIAL_SIZE:
				setInitialSize(INITIAL_SIZE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.NAME_SEQUENCE__NAMES:
				return names != null && !names.isEmpty();
			case CvmPackage.NAME_SEQUENCE__INITIAL_SIZE:
				return initialSize != INITIAL_SIZE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (initialSize: ");
		result.append(initialSize);
		result.append(')');
		return result.toString();
	}

} //NameSequenceImpl
